<?php
/**
 * Session class
 * 
 * This singleton represents the session
 *
 * @author Mathieu Pheulpin - sokaru91@gmail.com
 * @since 
 *
 */
class Mac_Session
{
    /**
     * Singleton instance
     * @var Session
     */
    private static $instance = null;
    
    /**
     * Namespaces list
     * @var array
     */
    private $namespaces = array();

    /**
     * Singleton getter
     * @return Session
     */
	private static function getInstance ()
	{
		if (self::$instance === null) {
            session_start();
			self::$instance = new self();
		}
		return self::$instance;
	}

    private function __construct () {}
    
    /**
     * Namespace getter
     * @param string $name Namespace name
     * @return Session_Namespace
     */
    public static function getNamespace ($name)
    {
        $session = self::getInstance()->namespaces;
        if (!isset($session[$name])) {
            $session[$name] = new Mac_Session_Namespace($name);
        }
        return $session[$name];
    }

}